<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/common/includes.jsp" %>
<%@ include file="/WEB-INF/view/inc.jsp" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<div class="dialog_form">
    <form id="fm" method="post" action="<%=contextPath%>/goodsInfo/saveAndUpdate">
        <input type="hidden" name="id" value="${goodsInfo.id}"/>
        <input type="hidden" id="imgs" value="${goodsInfo.img}"/><!--图片回显-->
        <input type="file" name="fileToUpload" id="fileToUpload"   style="display: none" onchange="sy_uploadGoodImg()" />

        <div class="dialog_item">
            <label>标题:</label>
            <input  name="title" class=" easyui-textbox" required="true"
                   validType="length[1,20]" value="${goodsInfo.title}">
        </div>
        <div class="dialog_item">
            <label>商品分类:</label>
            <input id="orderStatus_change" style="width: 200px;" name="goodsTypeId" editable="false" value="${goodsInfo.goodsTypeId}"
                   class="easyui-combobox" data-options="valueField : 'id',
            textField : 'title', url:'<%=contextPath%>/goodsType/select',
   panelHeight:'auto'
"/>
        </div>
        <div class="dialog_item">
            <label>原价:</label>
            <input  name="price" class=" easyui-numberbox"
                    validType="length[1,20]" value="${goodsInfo.price}">
        </div>
        <div class="dialog_item">
            <label>优惠价:</label>
            <input  name="currentPrice" class=" easyui-numberbox"
                    validType="length[1,20]" value="${goodsInfo.currentPrice}">
        </div>
        <div class="dialog_item">
            <label>折扣:</label>
            <input  name="discount" class=" easyui-numberbox"
                    validType="length[1,20]" value="${goodsInfo.discount}">
        </div>
        <div class="dialog_item">
            <label>保质期:</label>
            <input  name="validityDate" class=" easyui-textbox"
                    validType="length[1,20]" value="${goodsInfo.validityDate}">
        </div>
        <div class="dialog_item">
            <label>库存:</label>
            <input  name="stock" class=" easyui-textbox"
                    validType="length[1,20]" value="${goodsInfo.stock}">
        </div>

        <div class="dialog_item">
            <label>是否包邮:</label>
            <input name="isPost" editable="false" value="${goodsInfo.isPost}" required="true"
                   class="easyui-combobox" data-options="valueField : 'code',textField : 'name', url:'<%=contextPath%>/sys/codeItems/byCategoryCode?categoryCode=isPost',
								panelHeight:'auto'"  >
        </div>
         <div class="dialog_item">
            <label>快递描述:</label>
            <input  name="postDesc" class=" easyui-textbox"
                   validType="length[1,20]" value="${goodsInfo.postDesc}">
        </div>
        <div class="dialog_item">
            <label>商品描述:</label>
            <input  name="description" class=" easyui-textbox" style="height: 100px ; width: 300px" data-options="multiline:true"
                    validType="length[1,1000]" value="${goodsInfo.description}">
        </div>
        <div class="dialog_item">
            <label id="title">图片预览:</label>
            <div id="tpyl"> <!--图片回显框-->
                <ul>
                    <li>
                        <div>
                            <img class="uploadImgButton" src="/jslib/common/images/button/add.jpg" style="width: 90px;margin-top: 10px;margin-left: 10px;" onclick="loadImg()">
                        </div>
                    </li>
                </ul>
            </div>
        </div>
       <%-- <div class="dialog_item">
            <label>养生必读:</label>
            <input name="health" class="easyui-textbox" data-options="multiline:true"
                   validType="length[1,1000]" style="width:300px;height:100px" value="${cookbook.health}">
        </div>--%>
    </form>
</div>
<script>
    /** 图片回显加载
     *
     */
    $(function(){
        debugger;
       var imgs = $("#imgs").val();
       var imgtDiv = $("#tpyl ul");
       if(imgs!=undefined && imgs!=""){
           var imgArray = imgs.split(",");
           $.each(imgArray, function (i, item) {
               var   goodsImgArr = item.split("@");
               inserImg(item,imgtDiv,goodsImgArr[0]);
           })
      }
      loadMouseEventFun();
    })
    var sy_uploadGoodImg = function(){
        sy_uploadImg("/sys/upload/addDiagram");
    }
    /**
     * 上传成功后返回信息处理
     * @param result 返回信息
     */
    var successFun = function(result) {
        if (result == "0") {
            parent.$.messager.alert("错误", "请选择上传的图片");
        } else if (result == "1") {
            parent.$.messager.alert("错误", "有单个文件超过5M");
        } else {
            var resultDiv = $("#tpyl ul");
            if(result!=undefined && imgs!=""){
                var imgArray = result.split(",");
                $.each(imgArray, function (i, item) {
                    var   goodsImgArr = item.split("@");
                    inserImg(item,resultDiv,goodsImgArr[0]);
                })
            }
            loadMouseEventFun();//给回显图片绑定鼠标事件
        }
    }

/**
* 重写图片回显
* @param result
* @param resultDiv
* @param separator
 */
    var inserImg = function(result,resultDiv,imgSrc) {
        var id = result.substring(0, 32);
        var li = $("<li/>")
        var img_Div = $("<div class='img_Div' id=" + id + " style='width:100px;' />");
        var del_But_Div = $("<div class='img_del_button_div' onclick='delId(\"" + id + "\")' style='display: none' />");
        var but_Img = $("<img src='/jslib/common/images/button/close.png'  style='width: 10px;float: right;'>");
        var result_Img = $(" <img class='img_result' src='/file/" + imgSrc + " 'style='width: 100px;height: 100px;'>");
        var input = $("<input name='img' type='hidden' value=" + result + ">");
        del_But_Div.append(but_Img);
        img_Div.append(del_But_Div);
        img_Div.append(result_Img);
        img_Div.append(input);
        li.append(img_Div);
        resultDiv.append(li);//图片预览Div
}

</script>
</body>
</html>
